package cn.ww.teach.knowledge.nioKnowledge;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerAdapter;
import io.netty.channel.ChannelHandlerContext;
import io.netty.util.ReferenceCountUtil;

/**
 * Created by Wangwang on 2017/11/22.
 */
public class ClientReadHandler extends ChannelHandlerAdapter {
    @Override
    public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
        try {
            ByteBuf buffer = (ByteBuf) msg;
            byte[] bytes = new byte[buffer.readableBytes()];
            ByteBuf byteBuf = buffer.readBytes(bytes);
            System.out.println("===========================》》》》》》》》》》》》》》》client获取到Server的回复： " + new String(bytes));
        } catch (Exception e) {

        } finally {
            ReferenceCountUtil.release(msg);
        }
    }

}
